﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Smart.Common
{
    public partial class XProgressForm : DevExpress.XtraEditors.XtraForm
    {
        private bool _autoClose;
        private bool _die;
        private Form _form;

        public XProgressForm()
        {
            this._die = false;
            this._autoClose = false;
            InitializeComponent();
        }

        public XProgressForm(Form parent)
        {
            this._die = false;
            this._autoClose = false;
            this.InitializeComponent();
            this._form = parent;
        }

        public XProgressForm(UserControl parent)
        {
            this._die = false;
            this._autoClose = false;
            this.InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
        }

        public void SetProgressValue(int position)
        {
            this.SetProgressValue(position, this.lblTitle.Text);
        }

        public void SetProgressValue(string message)
        {
            this.SetProgressValue(this.progressBarControl1.Position, message);
        }

        public void SetProgressValue(int position, string message)
        {
            this.SetProgressValue(position, message, "Vui l\x00f2ng đợi trong gi\x00e2y l\x00e1t");
        }

        public void SetProgressValue(int position, string message, string caption)
        {
            if (!this._die)
            {
                if (!base.Visible)
                {
                    if (this._form != null)
                    {
                        base.Show(this._form);
                    }
                    else
                    {
                        base.Show();
                    }
                }
                this.lblMessage.Text = message;
                this.progressBarControl1.Position = position;
                this.lblTitle.Text = caption;
                base.Update();
                if ((position >= 100) && this.AutoClose)
                {
                    base.Visible = false;
                }
            }
        }

        public bool AutoClose
        {
            get
            {
                return this._autoClose;
            }
            set
            {
                this._autoClose = value;
            }
        }
    }
}